package com.authine.cloudpivot.ext.dto;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Optional;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "交易概要")
@Slf4j
public class Summary implements Serializable {

    @Schema(description = "品名")
    private String name;
    @Schema(description = "品牌")
    private String brand;
    @Schema(description = "规格")
    private String spec;
    @Schema(description = "型号")
    private String model;
    @Schema(description = "单位")
    private String unit;

    public static Summary conversion(String value) {

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            if (null == value) {
                return null;
            }
            return objectMapper.readValue(value, Summary.class);
        } catch (Exception ex) {
            log.error("---",ex);
            log.error("交易摘要JSON字符串转换失败: {}", value);
            return null;
        }
    }

}
